<template>
	<div>
		<!-- 面包屑导航区 -->
		<el-breadcrumb separator-class="el-icon-arrow-right">
			<el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>风险管理</el-breadcrumb-item>
			<el-breadcrumb-item>风险识别管理</el-breadcrumb-item>
		</el-breadcrumb>
		<!-- 卡片视图 -->

		<el-card>
			<!-- Tab栏 -->
			<el-form :model="riskdiscForm" :rules="riskdiscFormRules" ref="riskdiscFormRef" label-width="80px">

				<el-form-item label="风险名称" prop="title">
					<el-input placeholder="请输入风险名称" v-model="riskdiscForm.title"></el-input>
				</el-form-item>
				<el-form-item label="风险类别" prop="ranges">
					<el-input placeholder="请输入风险类别" v-model="riskdiscForm.ranges"></el-input>
				</el-form-item>
				<el-form-item label="风险描述" prop="probabi">
					<el-input placeholder="请输入风险描述" v-model="riskdiscForm.probabi"></el-input>
				</el-form-item>
				<el-form-item label="风险状态" prop="states">
					<el-select v-model="riskdiscForm.states" placeholder="请选择风险状态">
						<el-option label="未产生" value="未产生"></el-option>
						<el-option label="已产生未处理" value="已产生未处理"></el-option>
						<el-option label="已产生处理中" value="已产生处理中"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="是否可控" prop="judges">
					<el-select v-model="riskdiscForm.judges" placeholder="请选择是否可控">
						<el-option label="可控" value="可控"></el-option>
						<el-option label="不可控" value="不可控"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="风险征兆" prop="signs">
					<el-input placeholder="请输入风险征兆" v-model="riskdiscForm.signs"></el-input>
				</el-form-item>
				<el-form-item label="风险预案" prop="yuan">
					<el-input placeholder="请输入风险预案" v-model="riskdiscForm.yuan"></el-input>
				</el-form-item>
				<el-form-item label="风险后果" prop="methods">
					<el-input placeholder="请输入风险后果" v-model="riskdiscForm.methods"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="addMessage">确认</el-button>
					<el-button type="primary" @click="goback">取消</el-button>
				</el-form-item>

			</el-form>
		</el-card>
	</div>
</template>

<script>
	import _ from 'lodash'
	export default {
		data() {
			return {
				// 添加学习笔记的表单对象
				riskdiscForm: {
					id: '',
					title: '',
					states: '',
					judges: '',
					signs: '',
					methods: '',
					ranges: '',
					probabi: '',
					yuan: '',
					uid: JSON.parse(window.sessionStorage.getItem('Id')),
				},
				riskdiscFormRules: {
					title: [{
						required: true,
						message: '请输入项目名称',
						trigger: 'blur'
					}],
					states: [{
						required: true,
						message: '请选择风险状态',
						trigger: 'blur'
					}],
					judges: [{
						required: true,
						message: '请选择是否可控',
						trigger: 'blur'
					}],
					signs: [{
						required: true,
						message: '请输入风险征兆',
						trigger: 'blur'
					}],
					methods: [{
						required: true,
						message: '请输入风险后果',
						trigger: 'blur'
					}],
					ranges: [{
						required: true,
						message: '请输入风险类别',
						trigger: 'blur'
					}],
					probabi: [{
						required: true,
						message: '请输入风险描述',
						trigger: 'blur'
					}],
					yuan: [{
						required: true,
						message: '请输入风险预案',
						trigger: 'blur'
					}],
				}
			}
		},
		created() {

		},
		methods: {
			// 添加人员 完成后返回人员管理
			addMessage() {
				this.$refs.riskdiscFormRef.validate(async valid => {
					if (!valid) return this.$message.error('请填写必要的表单项！')
					// 将this.riskdiscForm进行深拷贝
					const forms = _.cloneDeep(this.riskdiscForm)
					const {
						data: spa
					} = await this.$http.post("addriskgaitu", forms)
					if (spa == "ok") {
						this.$message.success('风险添加成功!')
						this.$router.push('/risk_gaitu')
					} else {
						this.$message.error('风险添加失败!')
					}

				})
			},
			goback() {
				this.$router.push('/project_list')
			}

		},
	}
</script>

<style lang='less' scoped>
	.el-checkbox {
		margin: 0 8px 0 0 !important;
	}

	.previewImg {
		width: 100%;
	}

	.btnAdd {
		margin-top: 15px
	}
</style>
